package com.zzh.test;
  
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

 

 

/**
 * @Des     ps:不用生成服务器对象实体类
 * @author	张振华
 * @date	2017年4月28日  上午10:28:17
 * @version v1.0
 */
public class WebServiceClient { 
	private Logger logger = LoggerFactory.getLogger(WebServiceClient.class);
	private Client client; 
	private static WebServiceClient webclient = new WebServiceClient();
	
	 
	private WebServiceClient(){
		logger.info("webservice构造器------------------------------------"); 
		try{ 
			  
				DynamicClientFactory factory = DynamicClientFactory.newInstance();
				this.client = factory.createClient("http://127.0.0.1:9002/ServiceStart?wsdl");
			 
		}catch(Exception e){
			logger.info("错误的启动构造器"+e.getMessage());
		}
	}
	
	public static WebServiceClient getClient(){
		return webclient;
	}
	 
	 
	/**
	 * 调用webservice接口的方法
	 * @param methodName
	 * @param objects
	 * @return
	 * @throws Exception
	 */
	public String invoke(String methodName,Object...objects) throws Exception{
		logger.info("webservice 准备启动客户端...............................");
		String result = null;
		try{
			if(null != this.client){
				logger.info("webservice 客户端启动成功...............................");
				Object[] res=client.invoke(methodName,objects);
				logger.info("webservice 客户端返回结果..............................."+res);
				if(res != null && res[0] != null&&!res[0].equals("")){
					String json = res[0].toString();
 					result=res[0].toString();
				}
			}
		}catch(Exception e){
			throw new Exception("error:" + e.getMessage() , e);
		}
		return result;
	}
	
	
	public static void main(String[] args) throws Exception {
		WebServiceClient client = new WebServiceClient();
//		String path = "tom";
//		String respose = client.invoke("sayHello", path);
		String path = "c:/cv/51job_罗顺锋_Java高级工程师(931155337781.pdf";
		String respose = client.invoke("parseResume", path);
		System.out.println(respose); 
		 
		
		
	}
}
